<template>
  <el-table :data="students" style="width: 100%">
    <el-table-column label="编号" prop="id" />
    <el-table-column label="姓名" prop="name" />
    <el-table-column label="性别" prop="gender" />
    <el-table-column label="年龄" prop="age" />
    <el-table-column label="手机" prop="cellphone" />
    <el-table-column label="籍贯" prop="address" />
    <el-table-column align="right">
      <template #header>
        <el-input v-model="keyword" size="small" placeholder="搜索学生" />
      </template>
      <template #default="scope">
        <el-button size="small" @click="editStudent(scope.row)" >
          Edit
        </el-button>
        <el-button
            size="small"
            type="danger"
        >
          Delete
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination background layout="prev, pager, next" :total="total" :page-size="pageSize"
                 @current-change="loadStudent" />

  <!--    学生编辑对话框-->
  <el-dialog v-model="dialogFormVisible" title="学生信息" width="500">
    <el-form :model="student">
      <el-form-item label="姓名" >
        <el-input v-model="student.name" autocomplete="off" />
      </el-form-item>
      <el-form-item label="年龄" >
        <el-input v-model="student.age" autocomplete="off" />
      </el-form-item>
      <el-form-item label="性别" >
        <el-input v-model="student.gender" autocomplete="off" />
      </el-form-item>
      <el-form-item label="手机" >
        <el-input v-model="student.cellphone" autocomplete="off" />
      </el-form-item>
      <el-form-item label="籍贯" >
        <el-input v-model="student.address" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>


</template>

<script>
export default {
  name: "StudentView",
  data(){
    return {
      students: [],
      keyword: '',
      current: 1,    //当前页数
      pageSize: 10,  //页面大小
      total: 10,      //总数
      dialogFormVisible:false,
      student:{}
    }
  },
  methods:{
    loadStudent(current){
      this.current = current;
      this.$axios.get('/findStudentsPage?current=' + this.current + '&pageSize=' + this.pageSize)
          .then(result => {
            console.log('student',result.data)
            if(result.data.code === 200){
              this.students = result.data.data.data;
              this.total = result.data.data.total;
            }
          })
    },
    //编辑学生
    editStudent(stu){
      this.dialogFormVisible = true;
      //学生回显效果  stu --> string ---> 对象 深克隆
      this.student = JSON.parse(JSON.stringify(stu));
    }

  },
  mounted() {
    this.loadStudent(1)
  }
}
</script>

<style scoped>

</style>